package org.jeecg.common.util;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.fs.FileExtInfo;
import org.jeecg.common.fs.FileServiceManager;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.List;

/**
 * @Description: PmsUtil
 * @author: jeecg-boot
 */
@Slf4j
@Component
public class PmsUtil {

    public static String saveErrorTxtByList(List<String> msg, String name) {
        Date d = new Date();
        String fileName =  DateUtils.yyyymmddhhmmss.get().format(d) + Math.round(Math.random() * 10000) + ".txt";
        //遍历集合
        StringBuffer content = new StringBuffer();
        for (String s : msg) {
            //写数据
            if (s.indexOf("_") > 0) {
                String[] arr = s.split("_");
                content.append("第" + arr[0] + "行:" + arr[1]);
            } else {
                content.append(s);
            }
            content.append("\r\n");
        }
        String uploadUrl = FileServiceManager.getService().uploadFile(new ByteArrayInputStream(content.toString().getBytes(Charset.forName("utf-8"))), fileName, new FileExtInfo());
        return uploadUrl;
    }

}
